package controlisolation.lifecyclefsm;

import java.util.logging.Level;
import java.util.logging.Logger;
import controlisolation.lifecyclefsm.stateexecutor.StateWork;
import controlisolation.lifecyclefsm.stateexecutor.WorkStatus;

public abstract class LifeCycleFSMController {

    protected final static Logger _logger = Logger.getLogger(LifeCycleFSMController.class.getName());
    //protected boolean _running=false;
    protected LifeCycleFSM _lfsm;

    public static Logger getLogger() {
        return _logger;
    }

   
    /* Unified Error Control Method */
    protected void unifiedErrorControl(StateWork work) {
        try {
            getLfsm().stop();            
        } catch (Exception e) {
            _logger.log(Level.SEVERE, "Exceptions got in unified Error Control Method." + e.toString());
        }
        
        _logger.log(Level.SEVERE, "STOP REASONS:");
        if (!work.getWorkErrors().isEmpty()) {
                for (WorkStatus st : work.getWorkErrors()) {
                    _logger.log(Level.SEVERE, "\t" + st.toString());
                }
            }
        
    }

    public LifeCycleFSM getLfsm() {
        return _lfsm;
    }

    public void setLfsm(LifeCycleFSM lfsm) {
        this._lfsm = lfsm;
    }

    public abstract void controlCycle() throws Exception;
    
    
}
